package com.hou.controller;

import com.hou.parma.PageParam;
import com.hou.pojo.SeckillApplicationForm;
import com.hou.pojo.Vip;
import com.hou.service.ISeckillApplicationFormService;
import com.hou.vo.CaseVip;
import com.hzk.vo.RespBean;
import com.hzk.vo.RespBeanEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @auoter:jackh
 */
@RestController
@Controller
@RequestMapping("/hou")
public class appform {
    @Autowired
    ISeckillApplicationFormService iSeckillApplicationFormService;
    @RequestMapping("/app/select")
    public RespBean
    app5(@CaseVip Vip vip, PageParam pageParam){
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        List<SeckillApplicationForm> forms = iSeckillApplicationFormService.selectList(pageParam);
        Long along=iSeckillApplicationFormService.select1();
        if (forms==null){
            return RespBean.error(RespBeanEnum.NULL_FORM_ERROR);
        }
        return new RespBean(200,"SUCCESS",along,forms);
    }
    /**
     * 这个方法是按时间从古至今查询
     * @param pageParam
     * @return
     */

    @RequestMapping("/app/selectAsc")
    public RespBean app(@CaseVip Vip vip,PageParam pageParam){
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        List<SeckillApplicationForm> forms = iSeckillApplicationFormService.selectList_Asc(pageParam);
        if (forms==null){
            return RespBean.error(RespBeanEnum.NULL_FORM_ERROR);
        }
        return RespBean.success(forms);
    }

    /**
     * 这一个方法是倒叙查询：从今至古
     * @param pageParam
     * @return
     */
    @RequestMapping("/app/selectDesc")
    public RespBean app1(@CaseVip Vip vip,PageParam pageParam){
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        List<SeckillApplicationForm> forms = iSeckillApplicationFormService.selectList_Desc(pageParam);
        if (forms==null){
            return RespBean.error(RespBeanEnum.NULL_FORM_ERROR);
        }
        return RespBean.success(forms);
    }

    /**
     * 根据名称模糊查询
     * @param pageParam
     * @param name
     * @return
     */

    @RequestMapping("/app/selectByName")
    public RespBean app4(@CaseVip Vip vip,PageParam pageParam,String name){
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        List<SeckillApplicationForm> forms = iSeckillApplicationFormService.selectList_ByName(pageParam,name);
        Long selects = iSeckillApplicationFormService.selects(name);
        if (forms==null){
            return RespBean.error(RespBeanEnum.NULL_FORM_ERROR);
        }
        return new RespBean(200,"SUCCESS",selects,forms);
    }

    /**
     * 查询通过的用户
     * @param pageParam
     * @return
     */
    @RequestMapping("/app/selectByPass")
    public RespBean app2(@CaseVip Vip vip,PageParam pageParam){
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        List<SeckillApplicationForm> forms = iSeckillApplicationFormService.selectList_ByPass(pageParam);
        if (forms==null){
            return RespBean.error(RespBeanEnum.NULL_FORM_ERROR);
        }
        return RespBean.success(forms);
    }
    /**
     * 查询未通过的用户
     * @param pageParam
     * @return
     */
    @RequestMapping("/app/selectByFaile")
    public RespBean app3(@CaseVip Vip vip,PageParam pageParam){
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        List<SeckillApplicationForm> forms = iSeckillApplicationFormService.selectList_ByFaile(pageParam);
        if (forms==null){
            return RespBean.error(RespBeanEnum.NULL_FORM_ERROR);
        }
        return RespBean.success(forms);
    }
    @RequestMapping("/app/add")
    public RespBean add(@CaseVip Vip vip,SeckillApplicationForm seckillApplicationForm) {
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        //加这个查找id是否被注册，不然id值被注册了，直接报错400
        Long id = seckillApplicationForm.getId();
        SeckillApplicationForm s = iSeckillApplicationFormService.getById(id);
        if (s != null){
            return RespBean.error(RespBeanEnum.OPRATION_ERROR);
        }

        boolean save = iSeckillApplicationFormService.save(seckillApplicationForm);
        if (!save) {
            return RespBean.error(RespBeanEnum.OPRATION_ERROR);
        }

        return RespBean.success();
    }

    @RequestMapping("/app/show")
    public RespBean add0(@CaseVip Vip vip,Long id) {
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        SeckillApplicationForm select = iSeckillApplicationFormService.select(id);
        if (select!=null) {
            return RespBean.error(RespBeanEnum.OPRATION_ERROR);
        }
        return RespBean.success(select);
    }

    @RequestMapping("/app/update")
    public RespBean update(@CaseVip Vip vip,SeckillApplicationForm seckillApplicationForm) {
        boolean b = iSeckillApplicationFormService.updateById(seckillApplicationForm);
        if (!b) {
            return RespBean.error(RespBeanEnum.OPRATION_ERROR);
        }
        return RespBean.success();
    }


    @RequestMapping("/app/delete")
    public RespBean delete(@CaseVip Vip vip,Long id) {
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        boolean b = iSeckillApplicationFormService.removeById(id);
        if (!b) {
            return RespBean.error(RespBeanEnum.OPRATION_ERROR);
        }
        return RespBean.success();
    }

    @RequestMapping("/app/selectid")
    public RespBean selectid(@CaseVip Vip vip,Long id) {
        if (vip==null){
            return RespBean.error(RespBeanEnum.NULL_USER_ERROR);
        }
        SeckillApplicationForm s = iSeckillApplicationFormService.getById(id);
        if (s == null){
            return RespBean.error(RespBeanEnum.OPRATION_ERROR);
        }
        return RespBean.success(s);
    }

}
